package com.ftg.examsys.util;

import cn.hutool.core.util.CharsetUtil;
import cn.hutool.crypto.symmetric.SymmetricAlgorithm;
import cn.hutool.crypto.symmetric.SymmetricCrypto;

/**
 * 加密
 *
 * @author kangjx
 * @version 1.0
 * @date 2023/9/11 上午11:16
 */
public class HutoolUtilForMe {

    /**
     * 对密码进行加密的操作
     * @param password  明文密码
     * @return
     */
    public static String jiaMi(String password){
        byte[] key = ConstMess.MY_KEY.getBytes();
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
        byte[] encrypt = aes.encrypt(password);
        return aes.encryptHex(encrypt);
    }

    /**
     * 解密
     * @param encrypt  密文
     * @return
     */
    public String jieMi(String encrypt){
        byte[] key = ConstMess.MY_KEY.getBytes();
        SymmetricCrypto aes = new SymmetricCrypto(SymmetricAlgorithm.AES, key);
        byte[] decrypt = aes.decrypt(encrypt);
        return aes.decryptStr(decrypt, CharsetUtil.CHARSET_UTF_8);
    }

}
